package jftp; //打包

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import android.util.Log;

public class FtpServer extends Thread { // 继承线程
	public static final int FTP_PORT = 8000; // 默认端口
	ServerSocket ftpsocket = null;

	public void run() { // 重写RUN方法，创建多线程
		Socket client = null;
		try {
			ftpsocket = new ServerSocket(FTP_PORT); // 等待客户请求的服务器套接字
			Log.i(FtpServer.class.getName(),"listening port: " + FTP_PORT);
			for (;;) { // 无限循环，等客户端连接
				client = ftpsocket.accept();
				new FtpConnection(client).start();
			}
		} catch (Exception e) {
			Log.e(FtpServer.class.getName(),"error"+e.getMessage());
		}
	}

	@Override
	public void destroy() {
		if(ftpsocket!=null){
			try {
				ftpsocket.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
}